package com.graduationdesign.zengyan.graduationdesignapp.ui.base.errorhandle;

import android.support.annotation.NonNull;

import com.orhanobut.logger.Logger;

import io.reactivex.functions.Consumer;

/**
 * Created by ZengYan on 2018/4/21.
 *
 * @desc :
 */
public class ErrorConsumer<T extends Throwable> implements Consumer<T> {

    private final String tag;
    private BaseErrorView mErrorView;

    public ErrorConsumer(@NonNull BaseErrorView mErrorView , @NonNull String tag) {
        this.mErrorView = mErrorView;
        this.tag = tag;
    }

    @Override
    public void accept(T t)  {
        Logger.e(t,tag);
        if (t instanceof ServerException) {
            mErrorView.showServerError((ServerException) t);
        }else {
            mErrorView.showError(t);
        }
    }


}
